#ifndef BUTTONRELAYGP_H
#define BUTTONRELAYGP_H
#include <QtGui>
#include "button.h"
#include "buttonrelay.h"

#define GP_LAMP_RADIUS 40

class Pixmap : public QObject, public QGraphicsPixmapItem
{
    Q_OBJECT
    Q_PROPERTY(QPointF pos READ pos WRITE setPos)
public:
    Pixmap(const QPixmap &pix)
        : QObject(), QGraphicsPixmapItem(pix)
    {
        setCacheMode(DeviceCoordinateCache);
    }
};

class ButtonGP : public QGraphicsWidget
{
    Q_OBJECT
public:
    ButtonGP(Button& button,QGraphicsItem *parent, int lampradius);
    QRectF boundingRect() const
    {
        return QRectF(-mLampRadius, -mLampRadius, mLampRadius*2, mLampRadius*2);
    }

    QPainterPath shape() const
    {
        QPainterPath path;
        path.addEllipse(boundingRect());
        return path;
    }

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *);
    void setStatus(int status, uint stime, uint etime);
    const Button *button();

signals:
    void pressed();
    void hoverenter();
    void hoverleave();

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);

private:

    QPixmap _pix;
    QPixmap mPixON;
    QPixmap mPixOFF;
    QPixmap mPixUnknown;

    Button mButton;
    int mLampRadius;

public:
    uint mONStartTime;
    uint mONElapseTime;
};

#endif // BUTTONRELAYGP_H
